home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / impl / iint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  11.7 KB  |  376 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  iint.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. /*              iint.h          RD, 18.12.89 */
  16. /*     Modified for usage of c_varieties.h to provide
  17.     better portability between vanilla C, ANSI C and C++.
  18.             RD, 07.12.90.
  19.     Incorporated the definitions of c_varieties.h
  20.     as some compilers for Transputers aren't that
  21.     happy with c_varieties.h. Placed the compiler dependencies
  22.     in iint.h.
  23.             RD, 12.04.91.
  24.     Added special definitions for sparc, RD, 10/91.
  25.     Added "const" specifier for parameters, RD, 04.11.91.
  26.     Added functions cIasuint, cIaslong, cIasulong,
  27.         Iisint, Iisuint, Iislong, Iisulong,
  28.         intasI, uintasI, longasI, ulongasI, RD, 16.12.91
  29.     Put definition of INTTOPLACE into iutil.c, RD, 16.12.91
  30. */
  31.  
  32. #ifndef _IINT_H
  33. #define _IINT_H
  34.  
  35. /*     stdio.h is needed for the definition of FILE     */
  36.  
  37. #ifndef __PARC__
  38. #include <stdio.h>
  39. #endif
  40.  
  41. /*    Here are the compiler dependencies    */
  42.  
  43. #ifdef ATARI
  44. #define UNSIGNED16    unsigned int
  45. #define UNSIGNED32    unsigned long
  46. #define SIGNED32    long
  47. #include <malloc.h>
  48. #define MYMALLOC    malloc
  49. #define MYFREE    free
  50. #endif
  51.  
  52. #ifdef sun
  53. #ifdef sparc
  54. #define UNSIGNED16    unsigned short
  55. #define UNSIGNED32    unsigned long
  56. #define SIGNED32    long
  57. #define UNSIGNED64    unsigned long
  58. #define SIGNED64    long
  59. /* Wrong definition, but never used */
  60. #define USE_64_BIT_INTEGERS
  61. #define USE_SPARC_ASM
  62. #else
  63. #define UNSIGNED16    unsigned short
  64. #define UNSIGNED32    unsigned long
  65. #define SIGNED32    long
  66. #define USE_DOUBLEPLACE
  67. #endif
  68. /*
  69. #include <malloc.h>
  70. */
  71. #define MYMALLOC    malloc
  72. #define MYFREE    free
  73. #endif
  74.  
  75. #ifdef HELIOS
  76. #define USE_DOUBLEPLACE
  77. #define UNSIGNED16    unsigned short
  78. #define UNSIGNED32    unsigned long
  79. #define SIGNED32    long
  80. #include <stdlib.h>
  81. #define MYMALLOC    malloc
  82. #define MYFREE    free
  83. #endif
  84.  
  85. #ifdef __PARC__
  86. #define USE_64_BIT_INTEGERS
  87. #define USE_DOUBLEPLACE
  88. #define UNSIGNED16    unsigned short
  89. #define UNSIGNED32    unsigned int
  90. #define SIGNED32    int
  91. #define UNSIGNED64    unsigned long
  92. #define SIGNED64    long
  93. #include <stdlib.h>
  94. #define MYMALLOC    malloc
  95. #define MYFREE    free
  96. #endif
  97.  
  98. #ifdef NeXT
  99. #define USE_DOUBLEPLACE
  100. #define UNSIGNED16    unsigned short
  101. #define UNSIGNED32      unsigned long
  102. #define SIGNED32        long
  103. #include <stdlib.h>
  104. #define MYMALLOC        malloc
  105. #define MYFREE        free
  106. #endif
  107.  
  108. #ifndef UNSIGNED16
  109. #define USE_DOUBLEPLACE
  110. #define UNSIGNED16    unsigned short
  111. #define UNSIGNED32      unsigned long
  112. #define SIGNED32        long
  113. /*
  114. #include <malloc.h>
  115. */
  116. #define MYMALLOC        malloc
  117. #define MYFREE        free
  118. #endif
  119.  
  120. /*    Now let us see what are the biggest integers to use    */
  121.  
  122. #ifndef USE_64_BIT_INTEGERS
  123.     typedef    UNSIGNED16    PLACE, *pPLACE;
  124. #define LOGPLACE 16
  125. #else
  126.     typedef    UNSIGNED32    PLACE, *pPLACE;
  127. #define LOGPLACE 32
  128. #endif
  129.  
  130. /*    Here is the part of c_varieties.h we shall use    */
  131.  
  132. #ifndef C_VARIETIES_H
  133.  
  134. #ifdef __cplusplus
  135. #define EXTERN_FUNCTION( rtn, args ) extern "C" { rtn args; }
  136. #define _VOID_ /* anachronism */
  137. #else
  138. #ifdef __STDC__
  139. #ifdef __PARC__
  140. #define EXTERN_FUNCTION( rtn, args ) rtn()
  141. #define _VOID_
  142. #define const
  143. #else
  144. #define EXTERN_FUNCTION( rtn, args ) rtn args
  145. #define _VOID_ void
  146. #endif
  147. #else
  148. #define EXTERN_FUNCTION( rtn, args ) rtn()
  149. #define _VOID_
  150. #define const
  151. #endif
  152. #endif
  153.  
  154. #endif
  155.  
  156. /*    And now come some basic definitions    */
  157.  
  158. #ifndef BOOLEANDEF
  159. #define BOOLEANDEF
  160.     typedef int     BOOLEAN;
  161. #endif
  162. #ifndef FALSE
  163. #define FALSE 0
  164. #endif
  165. #ifndef TRUE
  166. #define TRUE 1
  167. #endif
  168. #ifndef NULL
  169. #define NULL 0
  170. #endif
  171.  
  172. #define PLUS 0
  173. #define MINUS 1
  174.  
  175. /*    This is the main data type    */
  176.  
  177. typedef struct {
  178.     PLACE          *vec;
  179.     int             maxlength, length, sign;
  180. }               Integer, *pInteger;
  181.  
  182. /*      Meaning of the function names:
  183.         I:      Integer
  184.         int:    int
  185.         as:     assign
  186.         pl:     plus
  187.         mi:     minus
  188.     eq:    equal
  189.     gt:    greater than
  190.     mu:    multiply
  191.     sl:    shift left
  192.     sr:    shift right
  193. */
  194.  
  195. EXTERN_FUNCTION(void cI, (Integer *));            /* Creator */
  196. EXTERN_FUNCTION(void cIasint, (Integer *, int));    /* Creator + Init int */
  197. EXTERN_FUNCTION(void cIasuint, (Integer *, unsigned int));
  198.     /* Creator + Init unsigned int */
  199. EXTERN_FUNCTION(void cIaslong, (Integer *, long));
  200.     /* Creator + Init long */
  201. EXTERN_FUNCTION(void cIasulong, (Integer *, unsigned long));
  202.     /* Creator + Init unsigned long */
  203. EXTERN_FUNCTION(void cIasI, (Integer *, const Integer *));
  204.     /* Creator + Init Int */
  205. EXTERN_FUNCTION(void cImaxlength, (Integer *, int));
  206.      /* maxlength wird vorgegeben */
  207. EXTERN_FUNCTION(void dI, (Integer *));            /* Destructor */
  208.  
  209. EXTERN_FUNCTION(Integer * ncI, (_VOID_));        /* new Integer + cI */
  210. EXTERN_FUNCTION(Integer * ncIasint, (int));    /* new Integer + cIasint */
  211. EXTERN_FUNCTION(Integer * ncIasI, (Integer *));    /* new Integer + cIasI */
  212. EXTERN_FUNCTION(Integer * ncImaxlength, (int));    /* new Integer + cImaxlength */
  213. EXTERN_FUNCTION(void ddI, (Integer *));        /* dI + delete Integer */
  214.  
  215. EXTERN_FUNCTION(void Ierror, (const char *));    /* Fehlermeldung */
  216. EXTERN_FUNCTION(char *Imalloc, (int));    /* Systemunabhaengiges malloc */
  217. EXTERN_FUNCTION(void Ifree, (char *));    /*     "    free */
  218.  
  219. EXTERN_FUNCTION(void IasI, (Integer *, const Integer *));    /* Zuweisung */
  220. EXTERN_FUNCTION(void Iasint, (Integer *, int));        /* Zuweisung einer int */
  221. EXTERN_FUNCTION(void Ias0, (Integer *));
  222. EXTERN_FUNCTION(void Ias1, (Integer *));
  223. #ifdef USE_THIS_LOT_OF_MACROS
  224. #define IAS0(A) ((A)->length=0, (A)->sign=PLUS)
  225. #define IAS1(A) ((A)->length=1, *((A)->vec)=1, (A)->sign=PLUS)
  226. #endif
  227. EXTERN_FUNCTION(BOOLEAN Iisint, (const Integer *));
  228. EXTERN_FUNCTION(BOOLEAN Iisuint, (const Integer *));
  229. EXTERN_FUNCTION(BOOLEAN Iislong, (const Integer *));
  230. EXTERN_FUNCTION(BOOLEAN Iisulong, (const Integer *));
  231. EXTERN_FUNCTION(int intasI, (const Integer *));
  232. EXTERN_FUNCTION(unsigned int uintasI, (const Integer *));
  233. EXTERN_FUNCTION(long longasI, (const Integer *));
  234. EXTERN_FUNCTION(unsigned long ulongasI, (const Integer *));
  235.  
  236. EXTERN_FUNCTION(int Ilog, (const Integer *));    /* Zweier Logarithmus */
  237. EXTERN_FUNCTION(int intlog, (int));    /* Zweier Logarithmus */
  238.  
  239. EXTERN_FUNCTION(void IasIplI, (Integer *, const Integer *, const Integer *));
  240.     /* Addition + */
  241. EXTERN_FUNCTION(void IasImiI, (Integer *, const Integer *, const Integer *));
  242.     /* Subtraktion - */
  243. EXTERN_FUNCTION(void IplasI, (Integer *, const Integer *));
  244.     /* Addition += */
  245. EXTERN_FUNCTION(void ImiasI, (Integer *, const Integer *));
  246.     /* Subtraktion -= */
  247. EXTERN_FUNCTION(void Ineg, (Integer *));
  248.     /* aendere das Vorzeichen */
  249. EXTERN_FUNCTION(void Iinc, (Integer *));        /* ++ */
  250. EXTERN_FUNCTION(void Idec, (Integer *));        /* -- */
  251.  
  252. EXTERN_FUNCTION(BOOLEAN IeqI, (const Integer *, const Integer *));
  253.     /* Vergleich == */
  254. EXTERN_FUNCTION(BOOLEAN IgtI, (const Integer *, const Integer *));
  255.     /* Groesser > */
  256. EXTERN_FUNCTION(BOOLEAN IneI, (const Integer *, const Integer *));
  257. EXTERN_FUNCTION(BOOLEAN IgeI, (const Integer *, const Integer *));
  258. EXTERN_FUNCTION(BOOLEAN IltI, (const Integer *, const Integer *));
  259. EXTERN_FUNCTION(BOOLEAN IleI, (const Integer *, const Integer *));
  260. EXTERN_FUNCTION(BOOLEAN Ige0, (const Integer *));
  261. EXTERN_FUNCTION(BOOLEAN Igt0, (const Integer *));
  262. EXTERN_FUNCTION(BOOLEAN Ile0, (const Integer *));
  263. EXTERN_FUNCTION(BOOLEAN Ilt0, (const Integer *));
  264. EXTERN_FUNCTION(BOOLEAN Ieq0, (const Integer *));
  265. EXTERN_FUNCTION(BOOLEAN Ieq1, (const Integer *));
  266. EXTERN_FUNCTION(int sign, (const Integer *)); /* returns +1, 0, -1 */
  267.  
  268. #ifdef USE_THIS_LOT_OF_MACROS
  269. #define INEI(A, B)    (!IeqI((A), (B)))
  270. #define IGEI(A, B)    (!IgtI((B), (A)))
  271. #define ILTI(A, B)    (IgtI((B), (A)))
  272. #define ILEI(A, B)    (!IgtI((A), (B)))
  273. #define IGE0(A)        ((A)->sign==PLUS)
  274. #define IGT0(A)        (((A)->sign==PLUS)&&((A)->length))
  275. #define ILE0(A)        (!(A)->length || ((A)->sign==MINUS))
  276. #define ILT0(A)        ((A)->sign==MINUS)
  277. #define IEQ0(A)        (!(A)->length)
  278. #define IEQ1(A)    ((*((A)->vec)==1)&&((A)->length==1)&&((A)->sign==PLUS))
  279. #endif
  280.  
  281. EXTERN_FUNCTION(void IasImuI, (Integer *, const Integer *, const Integer *));
  282.     /* Multiplikation * */
  283. EXTERN_FUNCTION(void ImuasI, (Integer *, const Integer *));
  284.     /* Multiplikation *= */
  285. EXTERN_FUNCTION(void IasImuP, (Integer *, const Integer *, PLACE));
  286.     /* Multiplikation mit PLACE */
  287. EXTERN_FUNCTION(void ImuasP, (Integer *, PLACE));
  288.  
  289. EXTERN_FUNCTION(void IasIsrint, (Integer *, const Integer *, unsigned int));
  290.     /* Shift nach rechts */
  291. EXTERN_FUNCTION(void Israsint, (Integer *, unsigned int));
  292.     /* Shift nach rechts */
  293. EXTERN_FUNCTION(void IasIslint, (Integer *, const Integer *, unsigned int));
  294.     /* Shift nach links */
  295. EXTERN_FUNCTION(void Islasint, (Integer *, unsigned int));
  296.     /* Shift nach links */
  297. EXTERN_FUNCTION(BOOLEAN Isr1, (Integer *));    /* Shift um eine Stelle */
  298. EXTERN_FUNCTION(BOOLEAN Ieven, (const Integer *));    /* ist a gerade? */
  299. #ifdef USE_THIS_LOT_OF_MACROS
  300. #define IEVEN(A)    (!(*((A)->vec) & 1))
  301. #endif
  302.  
  303. EXTERN_FUNCTION(PLACE uIdiasP, (Integer *, PLACE));
  304.     /* Division durch PLACE, kein Vorzeichen, Rest wird zurueckgegeben. */
  305. EXTERN_FUNCTION(PLACE IdiasP, (Integer *, PLACE));
  306.     /* Division durch PLACE, mit Vorzeichen, Rest wird zurueckgegeben. */
  307. EXTERN_FUNCTION(PLACE uIasIdiP, (Integer *, const Integer *, PLACE));
  308.     /* Division durch PLACE, kein Vorzeichen, Rest wird zurueckgegeben. */
  309. EXTERN_FUNCTION(PLACE IasIdiP, (Integer *, const Integer *, PLACE));
  310.     /* Division durch PLACE, mit Vorzeichen, Rest wird zurueckgegeben. */
  311. EXTERN_FUNCTION(void uIdiv, (Integer *q, Integer *r, const Integer *a, const Integer *b));
  312.     /* Division mit Rest a=bq+r, kein Vorzeichen */
  313. EXTERN_FUNCTION(void Idiv, (Integer *q, Integer *r, const Integer *a, const Integer *b));
  314.     /* Division mit Rest a=bq+r, mit Vorzeichen */
  315. EXTERN_FUNCTION(void IasIdiI, (Integer *, const Integer *, const Integer *));
  316.     /* Division, Quotient */
  317. EXTERN_FUNCTION(void IasIreI, (Integer *, const Integer *, const Integer *));
  318.     /* Division, Rest */
  319. EXTERN_FUNCTION(void IdiasI, (Integer *, const Integer *));
  320.     /* Division, Quotient */
  321. EXTERN_FUNCTION(void IreasI, (Integer *, const Integer *));
  322.     /* Division, Rest */
  323.  
  324. EXTERN_FUNCTION(int fscanI, (FILE *, Integer *));    /* Eingabe von Datei */
  325. EXTERN_FUNCTION(int fprintI, (FILE *, const Integer *));
  326.     /* Ausgabe auf Datei */
  327.  
  328. EXTERN_FUNCTION(void Idgcd, (Integer *d, const Integer *a, const Integer *b));
  329.     /* Euklidscher Algorithmus (Division)  d=gcd(a, b); */
  330. EXTERN_FUNCTION(void Ibgcd, (Integer *d, const Integer *a, const Integer *b));
  331.     /* binaerer gcd */
  332. #define Igcd    Ibgcd
  333.     /* Standard gcd    */
  334. EXTERN_FUNCTION(void Ielba,(Integer*d,Integer*u,Integer*v,const Integer*a,const Integer*b));
  335.     /* Euklid-Lenstra-Berlekamp  d=gcd(a, b)==ua+vb; */
  336. EXTERN_FUNCTION(void Ibelba,(Integer*d,Integer*u,Integer*v,const Integer*a,const Integer*b));
  337.     /* binaerer ELBA */
  338. EXTERN_FUNCTION(void Ireduce, (Integer *a, Integer *b));    /* Kuerze gcd */
  339.  
  340. EXTERN_FUNCTION(void IasrandomI, (Integer * a, const Integer * b));
  341.  /*
  342.   * Zufallsgenerator: waehle a zufaellig mit 0<=|a|<|b|, a->sign=b->sign.
  343.   * a und b muessen verschieden sein.
  344.   */
  345.  
  346. EXTERN_FUNCTION(char *wIdata1, (const Integer * a, int *l));
  347.  /*
  348.   * Erster Teil der Daten zum schnellen Speichern oder Verschicken einer
  349.   * Integer a: l = Anzahl der bytes; return Basisadresse.
  350.   */
  351. EXTERN_FUNCTION(char *wIdata2, (const Integer * a, int *l));
  352.  /* Zweiter Teil der Daten. */
  353. EXTERN_FUNCTION(char *rIdata1, (const Integer * a, int *l));
  354.  /*
  355.   * Zieladresse und Laenge fuer das Lesen oder Empfangen einer Integer,
  356.   * erster Teil.
  357.   */
  358. EXTERN_FUNCTION(char *rIdata2, (Integer * a, int *l));
  359.  /*
  360.   * Zweiter Teil zum Empfangen oder Lesen. Vor Aufruf dieser Funktion muss
  361.   * der erste Teil der Integer an die Adresse aus dem rIdata1-Aufruf
  362.   * geschrieben sein.
  363.   */
  364.  
  365. EXTERN_FUNCTION(int Itoa, (const Integer * n, char s[]));
  366. EXTERN_FUNCTION(int atoI, (char s[], Integer * n));
  367.  
  368. /*
  369. EXTERN_FUNCTION(_VOID_ Iprint_statistics, (_VOID_));
  370. */
  371.  
  372. EXTERN_FUNCTION(double Itodouble, (const Integer *));
  373.  
  374. #endif
  375.